using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;

namespace ProCodes.BugTracker.BugCatcher
{

    class CaptureBugScreenShot
    {
        private static Bitmap bmpScreenshot;
        private static Graphics gfxScreenshot;
        public string CaptureDesktopScreenShot()
        {
            // If the user has chosen a path where to save the screenshot
            string applicationBugImageFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ApplicationBugs";
            DirectoryInfo directoryInfo = new DirectoryInfo(applicationBugImageFile);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
            string bugImagePath = applicationBugImageFile;
            string bugImageFile = bugImagePath + "\\BUG_" + DateTime.Now.ToString("dd_MM_yyyy__hh_mm_tt") + ".png";

            // Set the bitmap object to the size of the screen
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            // Create a graphics object from the bitmap
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);
            // Take the screenshot from the upper left corner to the right bottom corner
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            // Save the screenshot to the specified path that the user has chosen
            bmpScreenshot.Save(bugImageFile, ImageFormat.Png);
            return bugImageFile;
        }
    }
}
